package com.wordcounter.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestParam;


@Controller
public class WordCounterController {
    // Hotswap测试字段
    private String testField = "Hotswap测试";

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index() {
        return "index";
    }

    @RequestMapping(value = "/count", method = RequestMethod.POST)
    public String countWords(@RequestParam("content") String content, Model model) {
        int charCount = content.length();
        int wordCount = content.trim().isEmpty() ? 0 : content.trim().split("\\s+").length;
        
        model.addAttribute("originalContent", content);
        model.addAttribute("charCount", charCount);
        model.addAttribute("wordCount", wordCount);
        
        return "result";
    }
} 